#ifndef __SN32F240_LED_DRIVER_H
#define __SN32F240_LED_DRIVER_H


/*_____ I N C L U D E S ____________________________________________________*/
#include <SN32F280.h>
#include <SN32F200_Def.h>

/*_____ D E F I N I T I O N S ______________________________________________*/

	#define		R_ROW1_HIGH		SN_GPIO0->BSET_b.BSET11 = 1;
	#define		R_ROW2_HIGH		SN_GPIO0->BSET_b.BSET8 = 1;
	#define		R_ROW3_HIGH		SN_GPIO3->BSET_b.BSET9 = 1;
	#define		R_ROW4_HIGH		SN_GPIO3->BSET_b.BSET12 = 1;
	#define		R_ROW5_HIGH		SN_GPIO3->BSET_b.BSET17 = 1;
	#define		R_ROW6_HIGH		SN_GPIO2->BSET_b.BSET11 = 1;
	#define		R_ROW7_HIGH		SN_GPIO3->BSET_b.BSET15 = 1;
	
	#define		G_ROW1_HIGH		SN_GPIO1->BSET_b.BSET5 = 1;
	#define		G_ROW2_HIGH		SN_GPIO3->BSET_b.BSET8 = 1;
	#define		G_ROW3_HIGH		SN_GPIO3->BSET_b.BSET11 = 1;
	#define		G_ROW4_HIGH		SN_GPIO3->BSET_b.BSET16 = 1;
	#define		G_ROW5_HIGH		SN_GPIO2->BSET_b.BSET10 = 1;
	#define		G_ROW6_HIGH		SN_GPIO2->BSET_b.BSET13 = 1;	
	#define		G_ROW7_HIGH		SN_GPIO1->BSET_b.BSET0 = 1;	
	
	#define		B_ROW1_HIGH		SN_GPIO1->BSET_b.BSET4 = 1;
	#define		B_ROW2_HIGH		SN_GPIO0->BSET_b.BSET9 = 1;
	#define		B_ROW3_HIGH		SN_GPIO3->BSET_b.BSET10 = 1;
	#define		B_ROW4_HIGH		SN_GPIO3->BSET_b.BSET13 = 1;
	#define		B_ROW5_HIGH		SN_GPIO3->BSET_b.BSET18 = 1;
	#define		B_ROW6_HIGH		SN_GPIO2->BSET_b.BSET12 = 1;
	#define		B_ROW7_HIGH		SN_GPIO1->BSET_b.BSET18 = 1;
	
	#define		COL0_HIGH			SN_GPIO0->BSET_b.BSET4 = 1;
	#define		COL1_HIGH			SN_GPIO0->BSET_b.BSET5 = 1;
	#define		COL2_HIGH			SN_GPIO2->BSET_b.BSET0 = 1;
	#define		COL3_HIGH			SN_GPIO2->BSET_b.BSET1 = 1;
	#define		COL4_HIGH			SN_GPIO2->BSET_b.BSET2 = 1;
	#define		COL5_HIGH			SN_GPIO2->BSET_b.BSET3 = 1;
	#define		COL6_HIGH			SN_GPIO0->BSET_b.BSET6 = 1;
	#define		COL7_HIGH			SN_GPIO0->BSET_b.BSET7 = 1;
	#define		COL8_HIGH			SN_GPIO2->BSET_b.BSET4 = 1;
	#define		COL9_HIGH			SN_GPIO2->BSET_b.BSET5 = 1;
	#define		COL10_HIGH		SN_GPIO2->BSET_b.BSET6 = 1;
	#define		COL11_HIGH		SN_GPIO2->BSET_b.BSET7 = 1;
	#define		COL12_HIGH		SN_GPIO2->BSET_b.BSET14 = 1;
	#define		COL13_HIGH		SN_GPIO2->BSET_b.BSET8 = 1;
	#define		COL14_HIGH		SN_GPIO2->BSET_b.BSET9 = 1;
	
	#define		COL15_HIGH		SN_GPIO0->BSET_b.BSET0 = 1;
	#define		COL16_HIGH		SN_GPIO0->BSET_b.BSET1 = 1;
	#define		COL17_HIGH		SN_GPIO0->BSET_b.BSET2 = 1;
	#define		COL18_HIGH		SN_GPIO0->BSET_b.BSET3 = 1;
	
	#define		COL_P0_MASK			0x00FF
	#define		COL_P1_MASK			0x0000
	#define		COL_P2_MASK			0x43FF
	#define		COL_P3_MASK			0x0000
		
	#define		ROW_P0_MASK			0x0B08
	#define		ROW_P1_MASK			0x40031
	#define		ROW_P2_MASK			0x3C00
	#define		ROW_P3_MASK			0x7BF00
	
	#define		ROW0_OUT_HIGH			SN_GPIO0->BSET |=(1<<11)
	#define		ROW0_OUT_LOW			SN_GPIO0->BCLR |=(1<<11)
	#define		ROW1_OUT_HIGH			SN_GPIO0->BSET |=(1<<10)
	#define		ROW1_OUT_LOW			SN_GPIO0->BCLR |=(1<<10)
	#define		ROW2_OUT_HIGH			SN_GPIO1->BSET |=(1<<2)
	#define		ROW2_OUT_LOW			SN_GPIO1->BCLR |=(1<<2)
	#define		ROW3_OUT_HIGH			SN_GPIO1->BSET |=(1<<1)
	#define		ROW3_OUT_LOW			SN_GPIO1->BCLR |=(1<<1)
	#define		ROW4_OUT_HIGH			SN_GPIO1->BSET |=(1<<0)
	#define		ROW4_OUT_LOW			SN_GPIO1->BCLR |=(1<<0)
	#define		ROW5_OUT_HIGH			SN_GPIO1->BSET |=(1<<11)
	#define		ROW5_OUT_LOW			SN_GPIO1->BCLR |=(1<<11)
	
	#define		ROW0_STATUS				(SN_GPIO1->DATA&(1<<14))
	#define		ROW1_STATUS				(SN_GPIO1->DATA&(1<<15))
	#define		ROW2_STATUS				(SN_GPIO1->DATA&(1<<19))
	#define		ROW3_STATUS				(SN_GPIO3->DATA&(1<<19))
	#define		ROW4_STATUS				(SN_GPIO0->DATA&(1<<19))
	#define		ROW5_STATUS				(SN_GPIO0->DATA&(1<<18))	
	
/*_____ M A C R O S ________________________________________________________*/
#define		LED_NUM				126
#define		LED_ALL_NUM		147
#define		LED_ROW_NUM		18
#define		KB_TABLE_COLUMN_SIZE		19
#define		KB_TABLE_ROW_SIZE				6

extern uint8_t rKeyCol_NO;
extern uint16_t iRPWM_Buf[];
extern uint16_t iGPWM_Buf[];
extern uint16_t iBPWM_Buf[];
extern uint8_t RPWM_Base_Buf[];
extern uint8_t GPWM_Base_Buf[];
extern uint8_t BPWM_Base_Buf[];
extern uint8_t rPWM_DutyBuf[];

extern uint8_t ROPWM_Base_Buf[];
extern uint8_t GOPWM_Base_Buf[];
extern uint8_t BOPWM_Base_Buf[];
extern uint8_t rOPWM_DutyBuf[];

extern uint8_t bmKeyScanTimer;

/*_____ D E C L A R A T I O N S ____________________________________________*/
void LED_Driver(void);
void All_Column_OutputHigh(void);
void All_LedRow_OutputHigh(void);
void All_LedRow_OutputLow(void);
void iLED_timer_case(void);
void Flash_KeyScan(void);
extern void LED_Update_Chat(void);

#endif	/*__SN32F240_LED_DRIVER_H*/
